package com.kuang.springcloud.service;


import com.kuang.springcloud.pojo.Dept;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

//失败 回调类
//负责降级 熔断
@Component
public class DeptClientServiceFallbackFactory  implements FallbackFactory {

    @Override
    public DeptClientService create(Throwable cause) {

        //返回的是一个类
        return new DeptClientService() {
            @Override
            public Dept queryById(Long id) {
                return new Dept().setDeptno(id).setDname("id==>"+id+"没有对应的信息，客户端提供了降级的信息").setDb_source("降级处理");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };


        //然后再去DeptClientService 加入降级注解处理
        //服务降级用feign实现 所以我们要去feign中配置
    }
}
